//
//  HMSearchFriend.swift
//  HealthMonitoring
//
//  Created by YTYanK on 2018/10/15.
//  Copyright © 2018年 YTYanK. All rights reserved.
//

import UIKit
import SwiftyJSON

class HMSearchFriend: HMViewController {

    let searchField = UITextField()
    let searchBtn = UIButton()
//    override func viewDidLoad() {
//        self.viewDidLoad()
//
//    }
//
    override func setupView() {
        self.title = "添加亲友"
        view.backgroundColor = configure.shareConfigure.HMColor2
        
        
        let sub1 = UIView()
        view.addSubview(sub1)
      
        sub1.topAlign(view: view)
        sub1.leadingAlign(view: view, predicate: "0")
        sub1.trailingAlign(view: view, predicate: "0")
        sub1.heightConstrain(predicate: "44")
        
        sub1.addSubview(searchField)
        sub1.addSubview(searchBtn)
        searchField.topAlign(view: sub1)
        searchField.leadingAlign(view: sub1)
        searchField.heightConstrain(predicate: "44")
        searchField.backgroundColor = UIColor.red
        searchField.placeholder = "请输入搜索账号"
        
        searchBtn.topAlign(view: sub1)
        searchBtn.leadingHorizontally(view: searchField, predicate: "0")
        searchBtn.trailingAlign(view: sub1)
        searchBtn.widthConstrain(predicate: "44")
        searchBtn.heightConstrain(predicate: "44")
        searchBtn.setTitle("搜索", for: .normal)
        searchBtn.backgroundColor = .blue
        searchBtn.addTarget(self, action: #selector(searchClick), for: UIControlEvents.touchUpInside)
    
    }
    
    
    @objc func searchClick(sender: UIButton) {
        print("======>>", sender)
        
        if (self.searchField.text?.count)! > 0 {
            NetRequestTool.shareInstance.met = .get
            let searchStr = self.searchField.text!
            NetRequestTool.request(url: "friend/search", parameters: ["phone": searchStr], success: { (json) in
                let details = HMDetails()
                details.userJsonData = json["data"]
                self.pushViewController(details)
                
            }, fail: { (code, msg) in
                
            }) { }
        }else {
            RKDropdownAlert.title("温馨提醒!", message: "请输入查询账号")
        }
        
    
    
        
    }
    
}


